
//
//  Jiankang_fenxi_vc.m
//  ainkjj
//
//  Created by MAX on 2020/4/28.
//  Copyright © 2020 zhiyiLiu. All rights reserved.
//

#import "Jiankang_fenxi_vc.h"
#import "ClMarkButton.h"
#import "WSDatePickerView.h"
#import "SKArchCutter.h"
#import "Bmi_setBabyBmi.h"
@interface Jiankang_fenxi_vc ()
@property (nonatomic, strong)UIScrollView *sv;
@property (nonatomic, copy) NSString *nan_nv_str;
@property (strong, nonatomic)UITextField *nicheng_tf;
@property (strong, nonatomic)UITextField *shengao_tf;
@property (strong, nonatomic)  UITextField *tizhong_tf;
@property (strong, nonatomic)  UIButton *selected_date_btn;
@property (nonatomic, strong)Bmi_setBabyBmi *setBabyBmi;
@property (nonatomic, strong)UILabel *saveTimeLb;
@property(nonatomic, strong) QMUIPopupContainerView *popupByAddSubview;
@property (strong, nonatomic)  CLMarkButton *nan_btn;
@property (strong, nonatomic)  CLMarkButton *nv_btn;
@end

@implementation Jiankang_fenxi_vc

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"填写健康信息";

    self.nan_nv_str = @"0";
    
    UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - Lzy_TabbarSafeBottomMargin)];
    [self.view addSubview:sv];
    self.sv = sv;
    sv.backgroundColor = UIColor.groupTableViewBackgroundColor;
    
    CGFloat leftPadding = 15;
    
    UILabel *lb1 = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, leftPadding, ScreenWidth - leftPadding * 2, 20)];
    [self.sv addSubview:lb1];
    
    
    NSMutableAttributedString *lb1_attr_str = [[NSMutableAttributedString alloc] initWithString:@"请填写宝宝信息"];
    [lb1_attr_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:16.0f] range:NSMakeRange(0, 7)];
    [lb1_attr_str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:251.0f/255.0f green:122.0f/255.0f blue:161.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 7)];
    lb1.attributedText = lb1_attr_str;
    
    UILabel *lb2 = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, CGRectGetMaxY(lb1.frame), ScreenWidth - leftPadding * 2, 20)];
    [self.sv addSubview:lb2];
    
    
    //
    NSMutableAttributedString *lb2_attr_str = [[NSMutableAttributedString alloc] initWithString:@"我们将根据您填写的信息为您分析宝宝健康指数"];
    [lb2_attr_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:13.0f] range:NSMakeRange(0, 21)];
    [lb2_attr_str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 21)];
    
    lb2.attributedText = lb2_attr_str;
    
    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(lb2.frame) + 20, ScreenWidth, 56)];
    [self.sv addSubview:v1];
    
    UIView *v1_v = [[UIView alloc] initWithFrame:CGRectMake(10, (56 -16) * 0.5, 4, 16)];
    [v1 addSubview:v1_v];
    v1.backgroundColor = UIColor.whiteColor;
    v1_v.layer.masksToBounds = YES;
    v1_v.layer.cornerRadius = 2;
    v1_v.backgroundColor = themeColor;
    
    UILabel *v1_lb = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v1_v.frame) + 10, 0, 100, CGRectGetHeight(v1.frame))];
    [v1 addSubview:v1_lb];
    //
    NSMutableAttributedString *v1_lb_attr_str = [[NSMutableAttributedString alloc] initWithString:@"基本信息"];
    [v1_lb_attr_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:15.0f] range:NSMakeRange(0, 4)];
    [v1_lb_attr_str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 4)];
    v1_lb.attributedText = v1_lb_attr_str;
    
    UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(v1.frame) + 1, ScreenWidth, 56)];
    [self.sv addSubview:v2];
    v2.backgroundColor = UIColor.whiteColor;
    
    UILabel *v2_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, 0, 100, CGRectGetHeight(v2.frame))];
    [v2 addSubview:v2_lb];
    //
    NSMutableAttributedString *v2_lb_attributedString = [[NSMutableAttributedString alloc] initWithString:@"名字"];
    [v2_lb_attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0f] range:NSMakeRange(0, 2)];
    [v2_lb_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 2)];
    v2_lb.attributedText = v2_lb_attributedString;
    
    UITextField *v2_tf = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v2_lb.frame), CGRectGetMinY(v2.frame), ScreenWidth - CGRectGetMaxX(v2_lb.frame) - leftPadding, CGRectGetHeight(v2.frame))];
    [self.sv addSubview:v2_tf];
    self.nicheng_tf = v2_tf;
    v2_tf.font = [UIFont systemFontOfSize:16];
    v2_tf.placeholder = @"请输入宝宝昵称";
    [v2_tf setTextAlignment:NSTextAlignmentRight];
    
    UIView *xb_v3 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(v2.frame) + 1, ScreenWidth, 56)];
    [self.sv addSubview:xb_v3];
    xb_v3.backgroundColor = UIColor.whiteColor;
    
    
    UILabel *v3_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, 0, 100, CGRectGetHeight(xb_v3.frame))];
    [xb_v3 addSubview:v3_lb];
    //
    NSMutableAttributedString *v3_lb_attributedString = [[NSMutableAttributedString alloc] initWithString:@"性别"];
    [v3_lb_attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0f] range:NSMakeRange(0, 2)];
    [v3_lb_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 2)];
    v3_lb.attributedText = v3_lb_attributedString;
    
    CLMarkButton *v3_nv_btn = [[CLMarkButton alloc] initWithFrame:CGRectMake(ScreenWidth - (leftPadding + 60), 0, 60, CGRectGetHeight(xb_v3.frame))];
    [xb_v3 addSubview:v3_nv_btn];
    [v3_nv_btn setTitle:@"女" forState:UIControlStateNormal];
    
    CLMarkButton *v3_nan_btn = [[CLMarkButton alloc] initWithFrame:CGRectMake(ScreenWidth - 2 * (leftPadding + CGRectGetWidth(v3_nv_btn.frame)), 0, CGRectGetWidth(v3_nv_btn.frame), CGRectGetHeight(xb_v3.frame))];
    [xb_v3 addSubview:v3_nan_btn];
    [v3_nan_btn setTitle:@"男" forState:UIControlStateNormal];
    
    
    // 设置单选按钮
    NSArray *radioArray = @[v3_nan_btn, v3_nv_btn];
    self.nan_btn = v3_nan_btn;
    self.nv_btn = v3_nv_btn;
    for (int i=0; i<radioArray.count; ++i)
    {
        CLMarkButton *button = radioArray[i];
        button.type = CLMarkTypeSingleRadio;
        button.groupId = 10001;
        button.tag = i;
        [button setTitleColor:UIColor.darkGrayColor forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button addTarget:self action:@selector(nan_nv_buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    [self nan_nv_buttonClick:v3_nan_btn];
    
    UIView *sr_v4 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(xb_v3.frame) + 1, ScreenWidth, 56)];
    [self.sv addSubview:sr_v4];
    sr_v4.backgroundColor = UIColor.whiteColor;
    
    
    UILabel *v4_lb1 = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, 0, 100, CGRectGetHeight(sr_v4.frame))];
    [sr_v4 addSubview:v4_lb1];
    //
    NSMutableAttributedString *v4_lb1_attributedString = [[NSMutableAttributedString alloc] initWithString:@"生日"];
    [v4_lb1_attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0f] range:NSMakeRange(0, 2)];
    [v4_lb1_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 2)];
    v4_lb1.attributedText = v4_lb1_attributedString;
    
    
    UIButton *v4_btn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 180, 0, 180, CGRectGetHeight(sr_v4.frame))];
    [sr_v4 addSubview:v4_btn];
    [v4_btn setTitleColor:UIColor.darkGrayColor forState:UIControlStateNormal];
    v4_btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [v4_btn setTitle:@"请选择出生日期" forState:UIControlStateNormal];
    [v4_btn addTarget:self action:@selector(chushengriqi_action:) forControlEvents:UIControlEventTouchUpInside];
    [v4_btn.titleLabel setTextAlignment:NSTextAlignmentRight];
    [v4_btn setContentMode:UIViewContentModeRight];
    [v4_btn setTitleEdgeInsets:UIEdgeInsetsMake(0, leftPadding, 0, -leftPadding)];
    self.selected_date_btn = v4_btn;
    
    UIView *v5 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(sr_v4.frame) + 20, ScreenWidth, 56)];
    [self.sv addSubview:v5];
    
    UIView *v5_v = [[UIView alloc] initWithFrame:CGRectMake(10, (56 -16) * 0.5, 4, 16)];
    [v5 addSubview:v5_v];
    v5.backgroundColor = UIColor.whiteColor;
    v5_v.layer.masksToBounds = YES;
    v5_v.layer.cornerRadius = 2;
    v5_v.backgroundColor = themeColor;
    
    UILabel *v5_lb = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v5_v.frame) + 10, 0, 100, CGRectGetHeight(v5.frame))];
    [v5 addSubview:v5_lb];
    //
    NSMutableAttributedString *v5_lb_attr_str = [[NSMutableAttributedString alloc] initWithString:@"成长信息"];
    [v5_lb_attr_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:15.0f] range:NSMakeRange(0, 4)];
    [v5_lb_attr_str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 4)];
    v5_lb.attributedText = v5_lb_attr_str;
    
    UILabel *saveTime_lb = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v5_lb.frame), 0, ScreenWidth - CGRectGetMaxX(v5_lb.frame)- leftPadding, CGRectGetHeight(v5_lb.frame))];
    [v5 addSubview:saveTime_lb];
    saveTime_lb.textColor = [UIColor darkGrayColor];
    saveTime_lb.font = [UIFont systemFontOfSize:14];
    [saveTime_lb setTextAlignment:NSTextAlignmentRight];
    self.saveTimeLb = saveTime_lb;
    
    UIView *v6 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(v5.frame) + 1, ScreenWidth, 56)];
    [self.sv addSubview:v6];
    v6.backgroundColor = UIColor.whiteColor;
    
    UILabel *v6_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, 0, 100, CGRectGetHeight(v6.frame))];
    [v6 addSubview:v6_lb];
    //
    NSMutableAttributedString *v6_lb_attributedString = [[NSMutableAttributedString alloc] initWithString:@"体重（kg）"];
    [v6_lb_attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0f] range:NSMakeRange(0, 2)];
    [v6_lb_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 6)];
    v6_lb.attributedText = v6_lb_attributedString;
    
    UITextField *v6_tf = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v6_lb.frame), CGRectGetMinY(v6.frame), ScreenWidth - CGRectGetMaxX(v6_lb.frame) - leftPadding, CGRectGetHeight(v6.frame))];
    [self.sv addSubview:v6_tf];
    self.tizhong_tf = v6_tf;
    v6_tf.font = [UIFont systemFontOfSize:16];
    v6_tf.placeholder = @"请输入体重";
    [v6_tf setTextAlignment:NSTextAlignmentRight];
    [v6_tf setKeyboardType:UIKeyboardTypeDecimalPad];
    UIView *v7 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(v6.frame) + 1, ScreenWidth, 56)];
    [self.sv addSubview:v7];
    v7.backgroundColor = UIColor.whiteColor;
    
    UILabel *v7_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, 0, 100, CGRectGetHeight(v7.frame))];
    [v7 addSubview:v7_lb];
    //
    NSMutableAttributedString *v7_lb_attributedString = [[NSMutableAttributedString alloc] initWithString:@"身高（cm）"];
    [v7_lb_attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:14.0f] range:NSMakeRange(0, 2)];
    [v7_lb_attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 6)];
    v7_lb.attributedText = v7_lb_attributedString;
    
    UITextField *v7_tf = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v7_lb.frame), CGRectGetMinY(v7.frame), ScreenWidth - CGRectGetMaxX(v7_lb.frame) - leftPadding, CGRectGetHeight(v7.frame))];
    [self.sv addSubview:v7_tf];
    self.shengao_tf = v7_tf;
    v7_tf.font = [UIFont systemFontOfSize:16];
    v7_tf.placeholder = @"请输入身高";
    [v7_tf setTextAlignment:NSTextAlignmentRight];
    [v7_tf setKeyboardType:UIKeyboardTypeDecimalPad];
    
    UIButton *liji_fenxi_btn = [[UIButton alloc] initWithFrame:CGRectMake(40, CGRectGetMaxY(v7.frame)  + 20, ScreenWidth - 40 * 2, 44)];
    [self.sv addSubview:liji_fenxi_btn];
    [liji_fenxi_btn setTitle:@"立即分析" forState:UIControlStateNormal];
    [liji_fenxi_btn setBackgroundImage:[Anktool gradient_img_create:rgb(255,107,149) toColor:rgb(255,163,191) frame:liji_fenxi_btn.frame] forState:UIControlStateNormal];
    liji_fenxi_btn.titleLabel.font = [UIFont systemFontOfSize:16];
    liji_fenxi_btn.layer.cornerRadius = CGRectGetHeight(liji_fenxi_btn.frame) * 0.5;
    liji_fenxi_btn.layer.masksToBounds = YES;
    
    [liji_fenxi_btn addTarget:self action:@selector(fenxi_action:) forControlEvents:UIControlEventTouchUpInside];

    [self.sv setContentSize:CGSizeMake(ScreenWidth, CGRectGetMaxY(liji_fenxi_btn.frame) + 10)];
    
    
    [self updateUIWith_lastPageBmi:self.lastPage_bmi];
    
}
- (void)updateUIWith_lastPageBmi:(Bmi_setBabyBmi *)lastPage_bmi{
    if (lastPage_bmi == nil) {
        return;
    }
    
    self.nicheng_tf.text = lastPage_bmi.data.name;
//    self.tizhong_tf.text = @(lastPage_bmi.data.weight).stringValue;
//    self.shengao_tf.text = @(lastPage_bmi.data.height).stringValue;
    
    if (lastPage_bmi.data.sex == 1) {
        [self nan_nv_buttonClick:self.nv_btn];
    }else{
        [self nan_nv_buttonClick:self.nan_btn];
    }
    
    [self.selected_date_btn setTitle:lastPage_bmi.data.birthday forState:UIControlStateNormal];;
}
- (void)create_fenxi_ui:(CGFloat)maxY{
    UIView *holder = [[UIView alloc] init];
    [self.sv addSubview:holder];
    holder.backgroundColor = UIColor.whiteColor;
    
    CGFloat leftPadding = 15;
    UIView *v8 = [[UIView alloc] initWithFrame:CGRectMake(0, maxY - 40, ScreenWidth, 56)];
    [self.sv addSubview:v8];
    
    UIView *v8_v = [[UIView alloc] initWithFrame:CGRectMake(10, (56 -16) * 0.5, 4, 16)];
    [v8 addSubview:v8_v];
    v8.backgroundColor = UIColor.whiteColor;
    v8_v.layer.masksToBounds = YES;
    v8_v.layer.cornerRadius = 2;
    v8_v.backgroundColor = themeColor;
    
    
    
    
    UILabel *v8_lb = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(v8_v.frame) + 10, 0, 100, CGRectGetHeight(v8.frame))];
    [v8 addSubview:v8_lb];
    //
    NSMutableAttributedString *v8_lb_attr_str = [[NSMutableAttributedString alloc] initWithString:@"报告分析"];
    [v8_lb_attr_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFang-SC-Medium" size:15.0f] range:NSMakeRange(0, 4)];
    [v8_lb_attr_str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:17.0f/255.0f green:17.0f/255.0f blue:17.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 4)];
    v8_lb.attributedText = v8_lb_attr_str;
    
    UILabel *bmi_lb = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(v8.frame) + leftPadding, ScreenWidth, 30)];
    [self.sv addSubview:bmi_lb];
    bmi_lb.textColor = appMainColor;
    bmi_lb.font = [UIFont boldSystemFontOfSize:26.0f];
    [bmi_lb setTextAlignment:NSTextAlignmentCenter];
    
    bmi_lb.text = @"BMI: 0.0";
    
    
    UILabel *shengao_tip_lb = [[UILabel alloc] initWithFrame:CGRectMake(80, CGRectGetMaxY(bmi_lb.frame) + 70, 40, 20)];
    [self.sv addSubview:shengao_tip_lb];
    shengao_tip_lb.text = @"身高";
    shengao_tip_lb.font = [UIFont systemFontOfSize:16];
    
    UILabel *tizhong_tip_lb = [[UILabel alloc] initWithFrame:CGRectMake(80, CGRectGetMaxY(shengao_tip_lb.frame) + 70, 40, 20)];
    [self.sv addSubview:tizhong_tip_lb];
    tizhong_tip_lb.text = @"体重";
    tizhong_tip_lb.font = [UIFont systemFontOfSize:16];
    
    NSArray *sg_arr = @[@"矮小",@"偏矮",@"标准",@"超高"];
    NSArray *color_arr = @[rgb(187,226,92), rgb(181,208,28), rgb(253,196,1), rgb(252,132,47)];
    NSArray *tz_arr = @[@"过轻",@"标准",@"过重",@"肥胖"];
    for (NSInteger i = 0; i < sg_arr.count; i++) {
        CGFloat btn_w = (ScreenWidth - 30 - CGRectGetMaxX(shengao_tip_lb.frame) - 10 - 3) * 0.25;
        UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(shengao_tip_lb.frame) + 10 + btn_w * i + i * 1, CGRectGetMidY(shengao_tip_lb.frame) - 10, btn_w, 22)];
        [self.sv addSubview:b];
        [b setTitle:sg_arr[i] forState:UIControlStateNormal];
        
        UIButton *b2 = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(shengao_tip_lb.frame) + 10 + btn_w * i + i * 1, CGRectGetMidY(tizhong_tip_lb.frame) - 10  , btn_w, 22)];
        [self.sv addSubview:b];
        [self.sv addSubview:b2];
        
        [b setTitle:sg_arr[i] forState:UIControlStateNormal];
        [b2 setTitle:tz_arr[i] forState:UIControlStateNormal];
        if (i == 0) {
            [SKArchCutter cuttingView:b cuttingDirection:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:b.frame.size.height / 2 borderWidth:0 borderColor:[UIColor whiteColor] backgroundColor:[UIColor colorNamed:@"aixiaoColor"]];
            [SKArchCutter cuttingView:b2 cuttingDirection:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:b2.frame.size.height / 2 borderWidth:0 borderColor:[UIColor whiteColor] backgroundColor:[UIColor colorNamed:@"aixiaoColor"]];
            
            b.layer.masksToBounds = b2.layer.masksToBounds = NO;
            
            
        }else if(i == sg_arr.count - 1){
            [SKArchCutter cuttingView:b cuttingDirection:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:b.frame.size.height / 2 borderWidth:0 borderColor:[UIColor whiteColor] backgroundColor:[UIColor colorNamed:@"chaogaoColor"]];
            
            [SKArchCutter cuttingView:b2 cuttingDirection:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:b2.frame.size.height / 2 borderWidth:0 borderColor:[UIColor whiteColor] backgroundColor:[UIColor colorNamed:@"chaogaoColor"]];
            b.layer.masksToBounds = b2.layer.masksToBounds = NO;
            
        }else{
            b.backgroundColor = b2.backgroundColor= color_arr[i];
            
        }
        if (i == self.setBabyBmi.data.heightIndex - 1) {
            
            // 使用方法 1，以 addSubview: 的形式显示到界面上
            QMUIPopupContainerView *popupByAddSubview = [[QMUIPopupContainerView alloc] init];
            [popupByAddSubview setBackgroundColor:[UIColor colorWithRed:253.0f/255.0f green:128.0f/255.0f blue:45.0f/255.0f alpha:1.0f]];

//            popupByAddSubview.imageView.image = [[UIImageMake(@"icon_emotion") qmui_imageResizedInLimitedSize:CGSizeMake(24, 24) resizingMode:QMUIImageResizingModeScaleToFill] qmui_imageWithTintColor:UIColor.qd_tintColor];
            popupByAddSubview.textLabel.text = [NSString stringWithFormat:@"%.2fcm", self.setBabyBmi.data.height];
            popupByAddSubview.textLabel.textColor = UIColor.whiteColor;
            popupByAddSubview.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
          
            popupByAddSubview.sourceView = b;// 相对于 button1 布局
            // 使用方法 1 时，显示浮层前需要先手动隐藏浮层，并自行添加到目标 UIView 上
            popupByAddSubview.hidden = YES;
            [self.sv addSubview:popupByAddSubview];
            [popupByAddSubview showWithAnimated:YES];

        }
        if(i == self.setBabyBmi.data.weightIndex - 1){
            // 使用方法 1，以 addSubview: 的形式显示到界面上
            QMUIPopupContainerView *popupByAddSubview = [[QMUIPopupContainerView alloc] init];
            popupByAddSubview.textLabel.textColor = UIColor.whiteColor;
            [popupByAddSubview setBackgroundColor:[UIColor colorWithRed:253.0f/255.0f green:128.0f/255.0f blue:45.0f/255.0f alpha:1.0f]];
// UIColor colorWithRed:237.0f/255.0f green:177.0f/255.0f blue:72.0f/255.0f alpha:1.0f]
            popupByAddSubview.imageView.image = [[UIImageMake(@"icon_emotion") qmui_imageResizedInLimitedSize:CGSizeMake(24, 24) resizingMode:QMUIImageResizingModeScaleToFill] qmui_imageWithTintColor:UIColor.qd_tintColor];
            popupByAddSubview.textLabel.text =  [NSString stringWithFormat:@"%.2fkg", self.setBabyBmi.data.weight];;
            popupByAddSubview.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
            
            popupByAddSubview.sourceView = b2;// 相对于 button1 布局
            // 使用方法 1 时，显示浮层前需要先手动隐藏浮层，并自行添加到目标 UIView 上
            popupByAddSubview.hidden = YES;
            [self.sv addSubview:popupByAddSubview];
            [popupByAddSubview showWithAnimated:YES];
        }
        
    }
    
    UILabel *fenxi_tip_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, CGRectGetMaxY(tizhong_tip_lb.frame) + 30, 120, 20)];
    fenxi_tip_lb.text = @"指数分析：";
    fenxi_tip_lb.textColor = UIColor.darkGrayColor;
    fenxi_tip_lb.font = [UIFont systemFontOfSize:16];
    [self.sv addSubview:fenxi_tip_lb];
    
    UILabel *fenxi_sg_lb = [[UILabel alloc] initWithFrame:CGRectMake(leftPadding, CGRectGetMaxY(fenxi_tip_lb.frame), ScreenWidth - 2 * leftPadding, 0)];
    [self.sv addSubview:fenxi_sg_lb];
    fenxi_sg_lb.numberOfLines = 0;
    fenxi_sg_lb.font = [UIFont systemFontOfSize:16];
    
    NSString *tipsStr = [NSString stringWithFormat:@"        %@\n\n        %@", self.setBabyBmi.data.heightAnalyze, self.setBabyBmi.data.weightAnalyze];
    CGSize size = [tipsStr boundingRectWithSize:CGSizeMake(fenxi_sg_lb.bounds.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:fenxi_sg_lb.font} context:nil].size;
    [fenxi_sg_lb setMj_size:size];
    fenxi_sg_lb.text = tipsStr;
    
    self.saveTimeLb.text = self.setBabyBmi.data.saveTime;
    bmi_lb.text = [NSString stringWithFormat:@"BMI:%.2f",self.setBabyBmi.data.bmiIndex];
    
    [self.sv setContentSize:CGSizeMake(ScreenWidth, CGRectGetMaxY(fenxi_sg_lb.frame) + 10)];
    
    
    holder.frame = CGRectMake(0, CGRectGetMaxY(v8.frame) + 1, ScreenWidth, CGRectGetMaxY(fenxi_sg_lb.frame) + 10 - CGRectGetMaxY(v8.frame) - 1);
    [self.sv setContentOffset:CGPointMake(0, CGRectGetMaxY(holder.frame) - (ScreenHeight - Lzy_TabbarSafeBottomMargin)) animated:YES];
    
}
- (void)fenxi_action:(UIButton *)sender{
        
    if ([Anktool strIsBlank:self.nicheng_tf.text]) {
        [QMUITips showInfo:@"请输入昵称"];
        
        return;
    }
    
    if ([[self.selected_date_btn currentTitle] isEqualToString:@"请选择出生日期"]) {
        [QMUITips showInfo:@"请选择出生日期"];
        
        return;
    }
    if ([Anktool strIsBlank:self.tizhong_tf.text]) {
        
        [QMUITips showInfo:@"请输入体重"];
        return;
    }
    
    if ([Anktool strIsBlank:self.shengao_tf.text]) {
        [QMUITips showInfo:@"请输入身高"];

        return;
    }
    [self.view endEditing:YES];
    NSString *deviceId = self.deviceId;
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:app_code forKey:@"appCode"];
    [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
    [dict setObject:deviceId forKey:@"deviceId"];
    [dict setObject:self.nicheng_tf.text forKey:@"name"];
    [dict setObject:self.nan_nv_str forKey:@"sex"];
    [dict setObject:self.selected_date_btn.currentTitle forKey:@"birthday"];
    [dict setObject:self.tizhong_tf.text forKey:@"weight"];
    [dict setObject:self.shengao_tf.text forKey:@"height"];

    //sender.userInteractionEnabled = NO;
    __block QMUITips *qmui_tip = [QMUITips showLoading:@"分析中..." inView:self.navigationController.view];
    
    [PPHTTPRequest req:@"java/app/bmi/setBabyBmi" parameters:dict success:^(id response) {
        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
        if ([error_code isEqualToString:@"0"]) {
            [qmui_tip hideAnimated:YES];
            Bmi_setBabyBmi *model = [Bmi_setBabyBmi mj_objectWithKeyValues:response];
            self.setBabyBmi = model;
            
            [self create_fenxi_ui:CGRectGetMaxY(sender.frame)];

            sender.hidden = YES;
            
            if ([self.delegate respondsToSelector:@selector(updateWithBmiInfo:)]) {
                [self.delegate updateWithBmiInfo:model];
            }

        }
        else{
            
            
            [qmui_tip showError:response[@"error_msg"] hideAfterDelay:2];
            
        }
        
    } failure:^(NSError *error) {
        [qmui_tip showError:[error localizedDescription] hideAfterDelay:2];
        
    }];
    
    
}
- (void)nan_nv_buttonClick:(CLMarkButton *)sender{
    [sender buttonDidClick];
    self.nan_nv_str = [[sender currentTitle] isEqualToString:@"男"] ? @"0" : @"1";
    DLog(@"%d", sender.selected);
}
- (void)chushengriqi_action:(UIButton *)sender {
    
    //年-月-日
    WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {
        
        NSString *dateString = [selectDate stringWithFormat:@"yyyy-MM-dd"];
        DLog(@"选择的日期：%@",dateString);
        [sender setTitle:dateString forState:UIControlStateNormal];
    }];
    datepicker.dateLabelColor = appMainColor;//年-月-日-时-分 颜色
    datepicker.datePickerColor = themeColor;//滚轮日期颜色
    datepicker.doneButtonColor = themeColor;//确定按钮的颜色
    datepicker.maxLimitDate = [NSDate date];
    [self.view endEditing:YES];
    [datepicker show];
}
@end
